package cn.kpi.service.sys.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kpi.dao.sys.MenuDao;
import cn.kpi.entity.sys.MenuEntity;
import cn.kpi.service.sys.IMenuService;

@Service
public class MenuServiceImpl implements IMenuService {
	@Autowired
private MenuDao menuDao;
	public int InsertEntity(MenuEntity entity)throws Exception
	{
		try{
			return menuDao.InsertEntity(entity);
		}
		catch(Exception ex){
			ex.printStackTrace();
			return -1;
		}
	}
	
	public List<MenuEntity> GetMenuList()throws Exception
	{
		try{
			return menuDao.GetMenuList();
		}
		catch(Exception ex){
			ex.printStackTrace();
			return null;
		}
	}
	public int InsertEntityProc(MenuEntity entity)throws Exception{
		try{
			Map<String, Object> map = new HashMap<String, Object>();
		    map.put("dmenuid", entity.getParentid());
		    map.put("dmenuname", entity.getMenuname());
		    map.put("dremark", entity.getRemark());
		    map.put("dmenutype", entity.getMenutype());
		    map.put("durl", entity.getUrl());
		    map.put("dicon", entity.getIcon());
		    map.put("dresult", 0);
		    menuDao.InsertEntityProc(map);
		    Object result=map.get("dresult");
		    return Integer.parseInt(String.valueOf(result));
		}
		catch(Exception ex){
			ex.printStackTrace();
			return -1;
		}
	}
	public int DeleteEntity(Long menuid) throws Exception{
		try{
			Map<String, Object> map = new HashMap<String, Object>();
		    map.put("mmenuid", menuid);
		    map.put("mresult", 0);
		    menuDao.DeleteEntity(map);
		    Object result=map.get("mresult");
		    return Integer.parseInt(String.valueOf(result));
		}
		catch(Exception ex){
			ex.printStackTrace();
			return -1;
		}
	}
}
